home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / bbs / twall62s.zip / input.mh < prev    next >
Text File  |  1996-07-28  |  2KB  |  108 lines

  1. #ifndef __XGETCH_MH
  2. #include <xgetch.mh>
  3. #endif
  4.  
  5. #ifndef __INPUT_MH
  6. #define __INPUT_MH
  7. #endif
  8.  
  9. void cutchar(ref string: line, int: index);
  10. void putchar(ref string: line, int: index, char: ch);
  11. void inputstring(ref string: line, int: maxlen);
  12.  
  13. void cutchar(ref string: line, int: index)
  14. {
  15.  string: outline;
  16.  
  17.  outline:=substr(line,1,index-1)+substr(line,index+1,(strlen(line)-index));
  18.  line:=outline;
  19. }
  20.  
  21. void putchar(ref string: line, int: index, char: ch)
  22. {
  23.  string: outline;
  24.  
  25.  outline:=substr(line,1,index-1);
  26.  outline[strlen(outline)+1]:=ch;
  27.  outline:=outline+substr(line,index,(strlen(line)-index+1));
  28.  line:=outline;
  29. }
  30.  
  31. void inputstring(ref string: line, int: maxlen)
  32. {
  33.  char: ch;
  34.  int: pos, len, tmp;
  35.  
  36.  start:;
  37.  if (line<>"") print(line);
  38.  len:=strlen(line);
  39.  pos:=len+1;
  40.  do
  41.  {
  42.   ch:=xgetch();      // get character from keyboard
  43.   if (ch=8)         // if character is backspace print it
  44.    {
  45.     if (pos>1)
  46.     {
  47.      print("\b \b");
  48.      tmp:=sys.current_col;
  49.      print(substr(line, pos, len-pos+1)+" ");
  50.      print(AVATAR_GOTO, (char)sys.current_row, (char)tmp);
  51.      pos:=pos-1;
  52.      len:=len-1;
  53.      cutchar(line,pos);
  54.     }
  55.    }
  56.   else if (ch=0)
  57.    {
  58.     ch:=xgetch();
  59.     if (ch=X_LEFT AND pos>1) // left
  60.        {
  61.         pos:=pos-1;
  62.         print(AVATAR_LEFT);
  63.        }
  64.     else if (ch=X_RIGHT AND pos<=len) // right
  65.        {
  66.         pos:=pos+1;
  67.         print(AVATAR_RIGHT);
  68.        }
  69.     else if (ch=X_HOME AND pos>1) // home
  70.        {
  71.         print(AVATAR_GOTO, (char)sys.current_row,
  72.               (char)(sys.current_col-pos+1));
  73.         pos:=1;
  74.        }
  75.     else if (ch=X_END AND pos<=len) // end
  76.        {
  77.         print(AVATAR_GOTO, (char)sys.current_row,
  78.               (char)(sys.current_col+(len-pos+1)));
  79.         pos:=len+1;
  80.        }
  81.     else if (ch=X_DELETE AND pos<=len) // del
  82.        {
  83.         cutchar(line,pos);
  84.         len:=len-1;
  85.         tmp:=sys.current_col;
  86.         print(substr(line,pos,(len-pos+1))+" ");
  87.         print(AVATAR_GOTO, (char)sys.current_row, (char)tmp);
  88.        }
  89.    }
  90.   else if (ch=13 OR ch=27) print();
  91.   else
  92.    {
  93.     if (len<maxlen)
  94.     {
  95.      tmp:=sys.current_col;
  96.      print(ch);
  97.      print(substr(line, pos, len-pos+1));
  98.      print(AVATAR_GOTO, (char)sys.current_row, (char)(tmp+1));
  99.      putchar(line,pos,ch);
  100.      pos:=pos+1;
  101.      len:=len+1;
  102.     }
  103.    }
  104.  }
  105.  while (ch<>13);
  106. }
  107.  
  108.